import Vue from 'vue'
import Router from 'vue-router'
import Root from '@/Root'
import Login from '../components/login'
import Store from '../components/Store'
import Order from '../components/Order'
import Task from '../components/Task'
import Commission from '../components/Commission'
import Operative from '../components/Operative'

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Root',
      component: Root,
      redirect: '/login',
      children: [
        {
          path: 'store',
          component: Store
        },
        {
          path: 'order',
          component: Order
        },
        {
          path: '/order/:tid',
          component: Order,
          props (route) {
            return {
              tid: route.params.tid
            }
          }
        },
        {
          path: 'task',
          component: Task
        },
        {
          path: '/task/:bid',
          component: Task,
          props (route) {
            return {
              bid: route.params.bid
            }
          }
        },
        {
          path: 'commission',
          component: Commission
        },
        {
          path: 'operative',
          component: Operative
        }
      ]
    },
    {
      path: '/login',
      component: Login
    }
  ]
})
